﻿@model IEnumerable<RedSand.Site.Models.ProductInfo>
<script type="text/javascript">
    function related_category(parent, child, sub, validate) {
        $('#' + parent).change(function () {
            load_category(parent, child, sub, validate);
        });
        load_category(parent, child, sub, validate);
    }

    function load_category(parent, child, sub, validate) {
        $.get("/category/selectlist?parent=" + $('#' + parent).val() + "&name=" + $('#' + child).attr('name') + "&id=" + child + (validate ? "&validate=true" : ""), function (data) {
            $('#' + child).replaceWith(data);
            $('.form input:text, .form input:password, .form select, .form textarea, .form input:password').addClass('input');
            if (sub) {
                related_category(child, sub, null, validate);
            }
        });
    }
    $(function () {
        related_category('sCategoryID2', 'sCategoryID1', 'sCategoryID0', false);
    });
</script>
<div class="panel">
    <div class="panel-header">
        <span>Product manager</span>
    </div>
    <div class="panel-content">
        <div class="panel-toolbar">
        <ul>
            <li>
                @Ajax.ActionLink("Add product", "create", null, AdminAjaxOptions.GetForm, new { @class = "btn-create" })
            </li>
            <li>
                <a href="#" class="btn-search">Search</a>
            </li>
            <li>
                @Ajax.ActionLink("Delete all selected", "delete", null, AdminAjaxOptions.DeleteRecords, new { @class = "btn-deletes" })
            </li>
        </ul>
    </div>
        <div class="panel-searchbox">
            @using (Ajax.BeginForm("List", AdminAjaxOptions.Search))
            {
                <div class="form-cell">
                    <label>Keyword</label>
                    @Html.TextBox("Keyword", (string)ViewBag.RouteValues.Keyword)
                </div>  
                <div class="form-cell">
                    <label>Maker</label>
                    @Html.Action("SelectList", "Maker", new { selectedValue = ViewBag.RouteValues.MakerID })
                </div>
                <div class="form-cell">
                    <label>Status</label>
                    @Html.DropDownList("Status", DropDownListHelper.GetStatusList(true, (byte?)ViewBag.RouteValues.Status))
                </div>
                <div class="clear"></div>
                <div class="form-cell">
                    <label>Parent category</label>
                    @Html.Action("SelectList", "Category", new { parent = 0, isCustomPc = false, name = "ParentCategoryID", id = "sCategoryID2", selectedValue = ViewBag.RouteValues.ParentCategoryID })
                </div>
                <div class="form-cell">
                    <label>Category</label>
                    @Html.Action("SelectList", "Category", new { parent = ViewBag.RouteValues.ParentCategoryID, isCustomPc = false, name = "CategoryID", id = "sCategoryID1", selectedValue = ViewBag.RouteValues.CategoryID })
                </div>
                <div class="form-cell">
                    <label>Sub category</label>
                    @Html.Action("SelectList", "Category", new { parent = ViewBag.RouteValues.CategoryID, isCustomPc = false, name = "SubCategoryID", id = "sCategoryID0", selectedValue = ViewBag.RouteValues.SubCategoryID })
                </div>
                <div class="form-cell width-auto">
                    <input type="submit" value="Search" class="button-small" />
                </div>
                <div class="clear">
                </div>
            }
        </div>
        @if (Model == null)
        {
            <div class="message warning">Data Empty</div>
        }
        else
        {
            <table class="table-list">
                <thead>
                    <tr>
                        <th class="width-25"><input type="checkbox" /></th>
                        <th>Name</th>
                        <th>Category</th>
                        <th>Maker</th>
                        <th class="center width-80">Status</th>
                        <th class="center width-80">Control</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model)
                    {
                        <tr>
                            <td>
                                <input value="@item.ProductID" type="checkbox" />
                            </td>
                            <td>
                                @item.Name
                            </td>
                            <td>
                                @Html.Action("GetName", "Category", new { id = item.CategoryID })
                            </td>
                            <td>
                                @Html.Action("GetName", "Maker", new { id = item.MakerID })
                            </td>
                            <td class="center">
                                @DropDownListHelper.GetStatusString(item.Status)
                            </td>
                            <td class="center">
                                @Ajax.ActionLink("Edit", "edit", new { id = item.ProductID }, AdminAjaxOptions.GetForm, new { @class = "btn-edit", title = "Edit" })
                                @Ajax.ActionLink("Delete", "delete", new { id = item.ProductID }, AdminAjaxOptions.DeleteRecord, new { @class = "btn-delete", title = "Delete" })
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
            <div class="pager-wrapper">
                @Ajax.Pager((int)ViewBag.TotalRecord, AdminAjaxOptions.Paging)
                <div class="pager-loading-panel"></div>
            </div>
        }
    </div>
</div>
